package transaction_date

import (
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 月底统计日
type MonthEndStatisticsDate struct {
	db *gorm.DB
}

// 初始化
func (m *MonthEndStatisticsDate) Init(db *gorm.DB) {
	m.db = db
}

// 是否是统计日
func (m *MonthEndStatisticsDate) IsStatisticsDate(transactionDate string) bool {
	var origin int = 0
	var stockNumber *int = &origin
	m.db.Raw("select count(*) from stock_index_month t where t.end_date=to_date(?,'yyyy-mm-dd')", transactionDate).Scan(&stockNumber)
	if *stockNumber > 0 {
		io.Infoln("日期[%s]是统计日", transactionDate)
		return true
	} else {
		return false
	}
}
